import 'package:flutter/material.dart';
import 'dart:async';

class LoginAnimationController {
  late AnimationController _fadeController;
  late AnimationController _slideController;
  late AnimationController _scaleController;
  late AnimationController _iconRotationController;
  late Animation<double> _fadeAnimation;
  late Animation<Offset> _slideAnimation;
  late Animation<double> _scaleAnimation;
  late Animation<double> _iconRotationAnimation;
  
  Timer? _floatingTimer;
  double _floatingOffset = 0.0;
  bool _floatingUp = true;

  Animation<double> get fadeAnimation => _fadeAnimation;
  Animation<Offset> get slideAnimation => _slideAnimation;
  Animation<double> get scaleAnimation => _scaleAnimation;
  Animation<double> get iconRotationAnimation => _iconRotationAnimation;
  double get floatingOffset => _floatingOffset;

  void initialize(TickerProvider vsync) {
    // فورمىنى كۆرسىتىش ئانىماتسىيەسى
    _fadeController = AnimationController(
      duration: const Duration(milliseconds: 800),
      vsync: vsync,
    );
    _fadeAnimation = CurvedAnimation(
      parent: _fadeController,
      curve: Curves.easeIn,
    );
    
    // فورما ئېلېمېنتلىرىنىڭ سىيرىلىپ كىرىش ئانىماتسىيەسى
    _slideController = AnimationController(
      duration: const Duration(milliseconds: 800),
      vsync: vsync,
    );
    _slideAnimation = Tween<Offset>(
      begin: const Offset(0.0, 0.5),
      end: Offset.zero,
    ).animate(CurvedAnimation(
      parent: _slideController,
      curve: Curves.easeOutCubic,
    ));
    
    // لوگونىڭ كېڭىيىش ئانىماتسىيەسى
    _scaleController = AnimationController(
      duration: const Duration(milliseconds: 1200),
      vsync: vsync,
    );
    _scaleAnimation = CurvedAnimation(
      parent: _scaleController,
      curve: Curves.elasticOut,
    );
    
    // ئىكوننىڭ ئايلىنىش ئانىماتسىيەسى
    _iconRotationController = AnimationController(
      duration: const Duration(milliseconds: 2000),
      vsync: vsync,
    );
    _iconRotationAnimation = Tween<double>(
      begin: 0.0,
      end: 2.0 * 3.14159, // كامىل ئايلانما (2π)
    ).animate(CurvedAnimation(
      parent: _iconRotationController,
      curve: Curves.easeOut,
    ));
    
    // لوگونىڭ لەيلەش ئانىماتسىيەسى
    _floatingTimer = Timer.periodic(const Duration(milliseconds: 50), (timer) {
      if (_floatingUp) {
        _floatingOffset += 0.1;
        if (_floatingOffset >= 5) {
          _floatingUp = false;
        }
      } else {
        _floatingOffset -= 0.1;
        if (_floatingOffset <= -5) {
          _floatingUp = true;
        }
      }
    });
    
    // ئانىماتسىيەلەرنى باشلاش
    _fadeController.forward();
    
    // نۆۋەت بويىچە ئانىماتسىيەلەرنى باشلاش
    Future.delayed(const Duration(milliseconds: 300), () {
      _slideController.forward();
    });
    
    Future.delayed(const Duration(milliseconds: 500), () {
      _scaleController.forward();
      _iconRotationController.forward().whenComplete(() {
        _iconRotationController.value = 0;
        _iconRotationController.stop();
      });
    });
  }

  void dispose() {
    _fadeController.dispose();
    _slideController.dispose();
    _scaleController.dispose();
    _iconRotationController.dispose();
    _floatingTimer?.cancel();
  }
} 